package com.example.net.udp;

import sun.awt.image.PixelConverter;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author zhaoyunlong
 * @date 2020/11/9
 * @description
 */
public class DUPServiceImpl {

    public static void main(String[] args) {

        try {
            DatagramSocket datagramSocket = new DatagramSocket(10002);
            byte[] data = new byte[1024];
            DatagramPacket datagramPacket = new DatagramPacket(data, data.length);
            datagramSocket.receive(datagramPacket);
            String value = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
            System.out.println(value);
            datagramSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
